package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.SettingsMapper;
import com.tanhua.model.domain.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author wjs
 * @version 1.0
 * @date 2021/12/24 0024 下午 4:21
 */

@DubboService
public class SettingsApiImpl implements SettingsApi{
    @Autowired
    private SettingsMapper settingsMapper;

    @Override
    public Settings findByUserId(Long userId) {
        LambdaQueryWrapper<Settings> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Settings::getUserId, userId);

        Settings settings = settingsMapper.selectOne(lqw);

        return settings;
//        QueryWrapper<Settings> qw = new QueryWrapper<>();
//        qw.eq("user_id",userId);
//        return settingsMapper.selectOne(qw);
    }

    @Override
    public void updateSettings(Settings settings) {
        settingsMapper.updateById(settings);
    }

    @Override
    public void saveSettings(Settings settings) {
        settingsMapper.insert(settings);
    }
}
